layui.use(['form','jquery'],function () {
    var form = layui.form,
        $ = layui.jquery;
    /**
     *添加区域
     */
    form.on("submit(addArea)",function(data) {
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        var obj = data.field;
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/areaMapperController/add',
            data: JSON.stringify(obj),
            dataType: 'json',
            contentType: 'application/json',
            success: function (data) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg("添加成功");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });

    $.ajax({
        url:'/servicemanController/all',
        type:'GET',
        success:function (res) {
            var options = "";
            $.each(res.data,function (index,item) {
                options +=  "<option value='"+item.serviceName+"'>"+item.serviceName+"</option>";
            });
            $("#serviceName").append(options);
            form.render();
        }
    });

    //添加区域负责人
    form.on("submit(addUnit)",function(obj) {
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        var data = obj.field;
        console.log(data);
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/unitController/add',
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json',
            success: function (res) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg("添加成功");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });
});